﻿/*
 * Created by SharpDevelop.
 * User: cszhangyi
 * Date: 2016/4/9
 * Time: 14:49
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Net;
using System.Text;
using System.IO;

namespace YMTSeller
{
	/// <summary>
	/// Description of YMTRequest.
	/// </summary>
	public class YMTRequest
	{
		public YMTRequest()
		{
		}
		
		public void RequestHeader() 
		{
			
		}
		
		public string get(string postUrl, string paramData, Encoding dataEncode) 
		{
			byte[] byteArray = dataEncode.GetBytes(paramData);
			HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(postUrl + "?" + paramData);
			
			webReq.Method = "GET";
			webReq.Proxy = new WebProxy("localhost:8888");
			webReq.UserAgent = "02ios====9.3===5F58DCEF-D449-46FF-81EF-02B569B9B260============================3.0.0=appStore========";
			//webReq.ContentLength = byteArray.Length;
            
            YMTResponse response = new YMTResponse();
            
            return response.getResponse((HttpWebResponse)webReq.GetResponse());
		}
		
		public string post(string postUrl, string paramData, Encoding dataEncode) 
		{
			byte[] byteArray = dataEncode.GetBytes(paramData);
			HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl));
			
			webReq.Method = "POST";
			webReq.Proxy = new WebProxy("localhost:8888");
			webReq.ContentType = "application/x-www-form-urlencoded";
			webReq.UserAgent = "02ios====9.3===5F58DCEF-D449-46FF-81EF-02B569B9B260============================3.0.0=appStore========";
			webReq.ContentLength = byteArray.Length;
			
			Stream newStream = webReq.GetRequestStream();
            newStream.Write(byteArray, 0, byteArray.Length);//写入参数
            newStream.Close();
            
            YMTResponse response = new YMTResponse();
            
            return response.getResponse((HttpWebResponse)webReq.GetResponse());
		}
	}
}
